const MD5 = require("./md5.min.js");
const ver = '1.0.6'
var vType = 'web'
var vCode = 10105
var token = '000'
var platform = 'web'
// var apiEntry = "http://pre.carelinker.com/clApi/entry"
var apiEntry = "https://platform.carelinker.com/clApi/entry"
var _request = function (method, api, data, success, fail) {
  data.platform = platform
  data.method = api[0]
  data.path = api[1]
  data.sign = MD5(api[0] + api[1] + MD5(vType))
  data.vCode = vCode
  data.vType = vType
  data.token = token
  wx.request({
    url: apiEntry,
    method: method,
    data: data,
    success: function (res) {
      // console.log('-----------------------------------------')
      // console.log(data)
      // console.log(res.data)
      // console.log('+++++++++++++++++++++++++++++++++++++++++')
      success(res.data)
      if (!res.data.success) {
        wx.showToast({
          title: '系统繁忙，请稍后再试。',
          image: '/images/error.png'
        })
      }
    },
    fail: fail
  })
}
var get = function(req){
  _request('GET', req)
}
var post = function (api, data, success, fail){
  _request('POST', api, data, success, fail)
}
var upload = function (api, data, success, fail) {
  _request('POST', api, data, success, fail)
}
module.exports = {
  get: get,
  post: post,
  upload,
  ver
}